package xing.service.controller;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xing.application.api.OwnerRegApi;
import xing.infrastructure.data.CallResult;

/*******************************************************************************************
 * 类描述：  
 *
 * @author: dustin
 * @date: 2017-11-08 14:00
 * @Description:
 * @version 1.0
 *
 *
 * Version    Date       ModifiedBy                 Content  
 * -------- ---------    ----------         ------------------------  
 * 1.0      2017/11/8     dst                               
 *******************************************************************************************
 */
@Api(value = "业主登记",description = "")
@RestController
@RequestMapping("/reg")
public class OwnerRegController {
    @Autowired
    OwnerRegApi ownerRegApi;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());


    @ApiOperation(value="业主登记列表", notes="")
    @ApiImplicitParams({@ApiImplicitParam(name = "searchText", value = "搜索文字", dataType = "String", paramType = "query" ),
            @ApiImplicitParam(name = "searchType", value = "搜索类型 (finished，unfinish，unstart，indo，expire,nopass)", dataType = "String", paramType = "query" ),
            @ApiImplicitParam(name = "compositeName", value = "排序名称 (startTime,endTime)", dataType = "String", paramType = "query" ),
            @ApiImplicitParam(name = "compositeType", value = "排序类型 （desc，asc）", dataType = "String", paramType = "query" )
    })
    @GetMapping("/list/{phone}")
    public String getReqList(@PathVariable String phone, @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                             @RequestParam(defaultValue = "") String searchText, @RequestParam(defaultValue = "") String searchType, @RequestParam(defaultValue = "") String compositeName, @RequestParam(defaultValue = "") String compositeType){

        String res;
        try {
            res = ownerRegApi.getRegList(phone,pageNo,pageSize,searchText,searchType,compositeName,compositeType);
        } catch (Exception e) {
            logger.error("获取业主登记列表失败 ",e);
            res = JSON.toJSONString( new CallResult(-1,"获取业主登记列表失败",null));
        }
        return res;
    }
    @ApiOperation(value="登记详情", notes="")
    @GetMapping("/detail/{id}")
    public String getReqList(@PathVariable int id){

        String res;
        try {
            res = ownerRegApi.getRegDetail(id);
        } catch (Exception e) {
            logger.error("获取登记详情失败 ",e);
            res = JSON.toJSONString( new CallResult(-1,"获取登记详情失败",null));
        }
        return res;
    }
    @ApiOperation(value="业主信息", notes="")
    @GetMapping("/ownerInfo/{ownerId}")
    public String getOwnerInfo(@PathVariable int ownerId){

        String res;
        try {
            res = ownerRegApi.getOwnerInfo(ownerId);
        } catch (Exception e) {
            logger.error("获取业主信息失败 ",e);
            res = JSON.toJSONString( new CallResult(-1,"获取业主信息失败",null));
        }
        return res;
    }
    @ApiOperation(value="业主信息统计", notes="")
    @GetMapping("/houseCount/{phone}")
    public String getOwnerInfo(@PathVariable String phone){

        String res;
        try {
            res = ownerRegApi.getHousesCount(phone);
        } catch (Exception e) {
            logger.error("业主信息统计失败 ",e);
            res = JSON.toJSONString( new CallResult(-1,"业主信息统计失败",null));
        }
        return res;
    }

}
